#!/usr/bin/env python
# coding: utf-8

'''
返回错误页面
'''
import tornado.web
import tornado.httpserver
import tornado.ioloop
from tornado.web import url,RequestHandler

class IndexHandler(RequestHandler):
    def get(self, *args, **kwargs):
        try:
            a = 1000 / 0
        except:
            '''send_error方法用于抛出错误，抛出的错误将会传递给write_error方法的kwargs参数，并处理'''
            self.send_error(title='除数不能为0', content='what the fuck!')
    def write_error(self, status_code, **kwargs):
        self.write('<h1>%s</h1>'%kwargs['title'])
        self.write('<p>%s</p>'%kwargs['content'])
if __name__ == '__main__':
    app = tornado.web.Application([
        url(r'/', IndexHandler, name='index'),
    ], debug=True)
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.bind(8000)
    http_server.start(1)
    tornado.ioloop.IOLoop.current().start()